package com.gsj.boot.service;

/**
 * @program: mybatisDriud
 * @description:
 * @author: 郭书江
 * @create: 2022-06-29 09:19
 **/
import com.gsj.boot.config.RedisUtils;
import com.gsj.boot.model.Users;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class UserService {

    public void add(String key, Users users){
        RedisUtils.set("user",users);
    }
    public Users get(String key){
        Users o = (Users)RedisUtils.get(key);
        log.info("从缓存中取"+o);
        return o ;
    }

    public void del(String key){
        RedisUtils.del(key);
    }

    public Users selectUsers(String key){
        return (Users)RedisUtils.get(key);
    }
    public List<Users> getUsers(String key,Long index){
        Object o = RedisUtils.lGetIndex(key,index);
        List<Users> users= (List<Users>)o;
        return users;
    }

    public void addList(List<Users> list){
        RedisUtils.lSet("users2",list);
    }

    public void updateList(String key,Integer count,List<Users> users){
        RedisUtils.lUpdateIndex(key,count,users);
    }

}